package com.牛客网.jd;

import java.util.Scanner;

public class 幸运数 {

	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		while(scanner.hasNext()){
			int numberinput=scanner.nextInt();
			int count=0;
			int number=1;
			while(number<=numberinput){
				String num=String.valueOf(number)+"p";
				int weicount=num.length();
				int sum1=0;
				for (int i = 0; i<weicount-1; i++) {
					sum1+=Integer.parseInt(num.substring(i,i+1));
				}
				String num2=Integer.toBinaryString(number)+"p";
				
				int weicount2=num2.length();
				int sum2=0;
				for (int i = 0; i<weicount2-1; i++) {
					sum2+=Integer.parseInt(num2.substring(i,i+1));
				}
				if(sum1==sum2){
					count++;
				}
				number++;
			}
			System.out.println(count);
		}
	}
}
